/*
 * @Description:
 * @Date: 2023-02-16 17:16:58
 */
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import qiankun from 'vite-plugin-qiankun'
// useDevMode 开启时与热更新插件冲突
const useDevMode = true // 如果是在主应用中加载子应用vite,必须打开这个,否则vite加载不成功, 单独运行没影响
// 打包分析
import { visualizer } from 'rollup-plugin-visualizer'
const lifecycle = process.env.npm_lifecycle_event

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    qiankun('lawsuit', { useDevMode }),
    lifecycle === 'report' ? visualizer({ open: true, brotliSize: true, filename: 'report.html' }) : null
  ],
  server: {
    port: 1001,
    cors: true // 默认启用并允许任何源
  },
  build: {
    outDir: 'lawsuit'
  },
  // base: '/',
  base: "/lawsuit/",
  resolve: {
    extensions: ['.js', '.jsx', '.vue', '.json'],
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
